/*
 * This file is part of Cockpit.
 *
 * Copyright (C) 2013 Red Hat, Inc.
 *
 * Cockpit is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * Cockpit is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Cockpit; If not, see <https://www.gnu.org/licenses/>.
 */

/* ---------------------------------------------------------------------------------------------------- */

@use "page";
@use "table";
@use "nav";
@use "@patternfly/patternfly/components/Menu/menu.css";
@use "@patternfly/patternfly/utilities/Text/text.css";
@use "@patternfly/patternfly/components/Icon/icon.css";

:root {
  --ct-color-host-accent: var(--pf-t--global--color--brand--default);
  --ct-topnav-background: var(--pf-t--global--background--color--secondary--default);
}

#shell {
    block-size: 100%;
}

/* Hacks on top for now */

html.index-page body {
  overflow: hidden;
}

#machine-change-auth > p {
  margin-block-end: 5px;
}

// Fix fingerprint layout
.add-host-fingerprint {
  margin-block-start: var(--pf-t--global--spacer--md);

  td {
    padding: 0;
    line-height: inherit;
    block-size: auto;
    vertical-align: middle !important;

    &:first-child {
      padding-inline-end: var(--pf-t--global--spacer--md);
    }
  }
}

.machine-key {
  margin: 0;
  white-space: pre-line;
  padding-block: var(--pf-t--global--spacer--xs);
  padding-inline: var(--pf-t--global--spacer--sm);
}

.login-setup-checkbox-wrapper {
  // Use a flex layout to better vertically align the contents to the grid
  display: flex;
}

#edit-machine-port {
  inline-size: 100px;
}

#connecting {
  block-size: 100%;
  background-color: var(--ct-global--palette--black-250);
  text-align: center;
  padding-block-start: 120px;
}

/* System information */

#systime-date-input,
#systime-time-hours,
#systime-time-minutes {
  display: inline;
}

/* index page */

.display-language-modal {
  /* Do not let the language menu expand to the end of the page */
  .pf-v6-c-menu__content {
    max-block-size: 20rem;
    overflow: auto;
  }
}

iframe.container-frame {
  border: none;
  inline-size: 100%;
}

// Page layout

$phone: 767px;
$desktop: $phone + 1px;

.page {
  --nav-width: 15rem;
  display: grid;
  inline-size: 100%;
  block-size: 100%;

  // Set masthead and toolbar to transparent, so the background shows through
  // (including the accent line)

  .pf-v6-c-masthead {
    --pf-v6-c-masthead--BackgroundColor: transparent;
  }

  .pf-v6-c-toolbar {
    --pf-v6-c-toolbar--BackgroundColor: transparent;
  }

  @media (max-width: $phone) {
    grid-template-areas: "main main main" "sidebar switcher header";
    grid-template-rows: 1fr 4rem;
    grid-template-columns: 1fr auto auto;
    overflow: hidden;

    .area-ct-subnav {
      grid-area: main;
    }

    .sidebar-toggle {
      grid-area: sidebar;
      display: flex;
    }

    > .header,
    > .navbar,
    > .sidebar-toggle {
      // Line on bottom, Base color (with subtle glow)
      background: linear-gradient(
        to top,
        var(--ct-color-host-accent),
        var(--ct-color-host-accent) 3px,
        transparent 3px
      );
      /* Toolbar needs visual separation between it and the content */
      border-block-start: var(--pf-t--global--border--width--regular) solid var(--pf-t--global--border--color--default);
    }

    // Remove excess padding from masthead in mobile
    .pf-v6-c-masthead {
      --pf-v6-c-masthead--inset: 0;
      --pf-v6-c-masthead--PaddingBlock: 0;
      --pf-v6-c-masthead--PaddingInline: 0;
      block-size: 100%;
    }
  }

  @media (min-width: $desktop) {
    // Shadow to the left, Line on top, Base color (with subtle glow)
    background: linear-gradient(
      to bottom,
      var(--ct-color-host-accent),
      var(--ct-color-host-accent) 3px,
      transparent 3px
    );

    grid-template-areas: "switcher switcher header" "sidebar main main";
    grid-template-rows: max-content 1fr;
    grid-template-columns: minmax(min-content, var(--nav-width)) auto 1fr;

    > .navbar {
      grid-area: switcher;
      margin-inline-end: calc(-1 * var(--pf-t--global--spacer--sm));
    }

    .sidebar {
      grid-area: sidebar;
    }

    .sidebar-toggle {
      grid-area: none;
      display: none;
    }

    .view-hosts .sidebar-hosts,
    .nav-system-menu {
      /* Top of the navbar should start when the curve of the content area ends. This means the search entry should be bumped down a bit. */
      padding-block-start: var(--pf-t--global--spacer--md);
    }
  }

  // Shrink nav for VMs @ 1024×768 (and below)
  @media (max-width: 1024px) and (max-height: 768px) and (orientation: landscape) {
    --nav-width: 14rem;
  }

  .area-ct-content {
    grid-area: main;
  }

  .header {
    grid-area: header;
  }
}

.hostkey-type {
  font-size: small;
}

.hostkey-verify-help {
  margin-block-end: 1.5em;
}

/* Alert fixups */
.modal-content .pf-v6-c-alert {
  text-align: start;
  margin-block-end: 24px;
}

.early-failure {
  block-size: 100%;
}

// Customize the about screen with the Cockpit logo
.pf-v6-c-about-modal-box {
  // Gray is best as it works in both light and dark mode
  // Ideally About modal should allow setting this through DOM instead of CSS
  // so we can color it easier.
  //
  // Or we can see about modifying it inline in scss and changing color there somehow
  --pf-v6-c-about-modal-box--BackgroundImage: url(../shell/images/cockpit-icon-gray.svg);
  --pf-v6-c-about-modal-box--BackgroundPosition: max(25rem, 143%) 10rem;
  --pf-v6-c-about-modal-box--BackgroundSize--min-width: 786px;

  .pf-v6-c-content {
    /* Don't wrap package names */
    --pf-v6-c-content--dl--GridTemplateColumns--dt: auto;
    /* Tidy up the vertical space usage between packages */
    --pf-v6-c-content--dl--RowGap: var(--pf-t--global--spacer--sm);
  }

  [dir="rtl"] {
    --pf-v6-c-about-modal-box--BackgroundPosition: calc(100% - 30rem) 10rem;
  }
}
